package app.handler;

import app.utils.RedisTemplateUtils;
import app.vo.ResultResponse;
import com.alibaba.fastjson.JSON;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class ReqLogoutSuccessHandler implements LogoutSuccessHandler{
    @Autowired
    private ResultResponse resultResponse;
    @Autowired
    private RedisTemplateUtils redisTemplateUtils;

    //注销成功处理程序
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException {
        resultResponse.setCode(200);
        resultResponse.setMessage("注销成功");
        ResultResponse resultResponse = new ResultResponse(this.resultResponse.getCode(), this.resultResponse.getMessage(),this.resultResponse.getState(), this.resultResponse.getData());
        httpServletResponse.setCharacterEncoding("UTF-8");
        redisTemplateUtils.del("imgSwipeSuccess");
        redisTemplateUtils.del("XPosition");
        redisTemplateUtils.del("phoneCode");
        httpServletResponse.getWriter().write(JSON.toJSONString(resultResponse));
    }
}